activerecord: Instance self type for the :default option argument in belongs_to #1045
activerecord: Instance self type for the :default option argument in belongs_to #1045felixefelip wants to merge 1 commit into
:default option argument in belongs_to #1045Conversation
:default option argument in Active Record belongs_to
:default option argument in Active Record belongs_to :default option argument in Active Record belongs_to
| extend ::ActiveRecord::Validations::ClassMethods | ||
| extend ::ActiveSupport::Callbacks::ClassMethods | ||
|
|
||
| type belongs_to_default[T] = ^(T) [self: T] -> ::ActiveRecord::Base? |
There was a problem hiding this comment.
For the Active Record 6, I couldn't find a test setup, so I didn't add a test to this change. But if it's necessary, I'd be happy to add tests for this version as well.
|
@felixefelip Thanks for your contribution! Please follow the instructions below for each change. Available commandsYou can use the following commands by commenting on this PR.
|
4b9153c to
7c2914b
Compare
:default option argument in Active Record belongs_to :default option argument in belongs_to

In Active Record
belongs_tooption:default, the self type in block is the instance type instead the singleton type. Doc: https://apidock.com/rails/ActiveRecord/Associations/ClassMethods/belongs_to#:~:text=belongs%5Fto%20%3Aaccount%2C%20default%3A%20%2D%3E%20%7B%20company%2Eaccount%20%7DIn applications like Fizzy, it's a very common use.
Without this fix, we have this output error: